package GUI;

import javax.swing.JPanel;
import java.awt.FlowLayout;
import javax.swing.JLabel;
import java.awt.Font;

import javax.swing.DefaultComboBoxModel;
import javax.swing.SwingConstants;
import javax.swing.JComboBox;
import javax.swing.JButton;

import common.Statistics;

import MessagePacks.getStatisticReport;

import java.awt.event.ItemListener;
import java.awt.event.ItemEvent;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Random;

/**
 *@author Juan Alapin - 324507516
 *@author Giora Yaffe - 036551281
 *@author Shachar Gritzman - 300174026
 *@author Nir Porat - 021515580
*/

public class LatencyReport extends MasterGUI {
	
	private static final long serialVersionUID = 1L;
	private MainGUI mainGui;
	private String[] days31;
	private String[] days30;
	private String[] days28;
	private String[] years;
	private String[] months;
	private String[] periods;
	private String DaysStart[];
	private String DaysEnd[];
	public JComboBox StartYearcomboBox;
	public JComboBox StartMonthcomboBox;
	public JComboBox StartDaycomboBox;
	public JComboBox EndYearcomboBox;
	public JComboBox EndMonthcomboBox;
	public JComboBox EndDaycomboBox;
	public JComboBox PeriodcomboBox;
	public JPanel reportPanel;
	public final static int MoodleData=1;
	public final static int WebsiteData=2;
	public final static int LibraryData=3;
	public final static int InformationSystemData=4;
	public final static int ComputersData=5;
	public Statistics Moodle;
	public Statistics Website;
	public Statistics Library;
	public Statistics InformationSystem;
	public Statistics Computers;
	public JLabel lblMoodleMedian;
	public JLabel lblWebsiteMedian;
	public JLabel lblLibraryMedian;
	public JLabel lblInfoMedian;
	public JLabel lblCompMedian;
	public JLabel lblMoodleMean;
	public JLabel lblWebsiteMean;
	public JLabel lblLibraryMean;
	public JLabel lblInfoMean;
	public JLabel lblCompMean;
	public JLabel lblMoodleStdev;
	public JLabel lblWebsiteStdev;
	public JLabel lblLibraryStdev;
	public JLabel lblInfoStdev;
	public JLabel lblCompStdev;
	public ArrayList<String> MoodleList;
	public ArrayList<String> WebsiteList;
	public ArrayList<String> LibraryList;
	public ArrayList<String> InfoList;
	public 	ArrayList<String> CompList;
	private getStatisticReport statReportPck;
	private getStatisticReport statReportPck1;
	
	public LatencyReport(MainGUI maingui) {
		super(maingui);
		MoodleList=new ArrayList<String>();
		WebsiteList=new ArrayList<String>();;
		LibraryList=new ArrayList<String>();;
		InfoList=new ArrayList<String>();;
		CompList=new ArrayList<String>();;
		
		JPanel titlePanel = new JPanel();
		titlePanel.setBounds(0, 0, 884, 40);
		getContentPane().add(titlePanel);
		
		JLabel lblTitle = new JLabel("Latency Report");
		lblTitle.setFont(new Font("Dialog", Font.BOLD, 16));
		titlePanel.add(lblTitle);
		
		JPanel panelReport = new JPanel();
		panelReport.setBounds(866, 51, -678, 540);
		getContentPane().add(panelReport);
		panelReport.setLayout(null);
		
		JLabel lblMoodle = new JLabel("Moodle:");
		lblMoodle.setHorizontalAlignment(SwingConstants.RIGHT);
		lblMoodle.setBounds(198, 97, 46, 14);
		getContentPane().add(lblMoodle);
		
		JLabel lblWebsite = new JLabel("WebSite:");
		lblWebsite.setHorizontalAlignment(SwingConstants.RIGHT);
		lblWebsite.setBounds(198, 139, 46, 14);
		getContentPane().add(lblWebsite);
		
		JLabel lblLibrary = new JLabel("Library:");
		lblLibrary.setHorizontalAlignment(SwingConstants.RIGHT);
		lblLibrary.setBounds(198, 184, 46, 14);
		getContentPane().add(lblLibrary);
		
		JLabel lblComputers = new JLabel("Computers:");
		lblComputers.setHorizontalAlignment(SwingConstants.RIGHT);
		lblComputers.setBounds(181, 227, 63, 14);
		getContentPane().add(lblComputers);
		
		JLabel lblInformation = new JLabel("Information:");
		lblInformation.setHorizontalAlignment(SwingConstants.RIGHT);
		lblInformation.setBounds(169, 270, 75, 14);
		getContentPane().add(lblInformation);
		
		JLabel lblStation = new JLabel("Station");
		lblStation.setHorizontalAlignment(SwingConstants.CENTER);
		lblStation.setBounds(181, 283, 63, 14);
		getContentPane().add(lblStation);
		
		JLabel lblMedian = new JLabel("Median");
		lblMedian.setFont(new Font("Tahoma", Font.BOLD, 11));
		lblMedian.setHorizontalAlignment(SwingConstants.CENTER);
		lblMedian.setBounds(285, 72, 56, 14);
		getContentPane().add(lblMedian);
		
		JLabel lblStandardDeviation = new JLabel("Standard Deviation");
		lblStandardDeviation.setFont(new Font("Tahoma", Font.BOLD, 11));
		lblStandardDeviation.setHorizontalAlignment(SwingConstants.CENTER);
		lblStandardDeviation.setBounds(390, 72, 109, 14);
		getContentPane().add(lblStandardDeviation);
		
		JLabel lblMean = new JLabel("Mean");
		lblMean.setFont(new Font("Tahoma", Font.BOLD, 11));
		lblMean.setHorizontalAlignment(SwingConstants.CENTER);
		lblMean.setBounds(538, 72, 63, 14);
		getContentPane().add(lblMean);
		
		lblMoodleMedian = new JLabel(Double.toString(myAnalyzer(MoodleData)));
		lblMoodleMedian.setHorizontalAlignment(SwingConstants.CENTER);
		lblMoodleMedian.setBounds(295, 97, 36, 14);
		getContentPane().add(lblMoodleMedian);
		
		lblWebsiteMedian = new JLabel(Double.toString(myAnalyzer(WebsiteData)));
		lblWebsiteMedian.setHorizontalAlignment(SwingConstants.CENTER);
		lblWebsiteMedian.setBounds(295, 139, 36, 14);
		getContentPane().add(lblWebsiteMedian);
		
		lblLibraryMedian = new JLabel(Double.toString(myAnalyzer(LibraryData)));
		lblLibraryMedian.setHorizontalAlignment(SwingConstants.CENTER);
		lblLibraryMedian.setBounds(295, 184, 36, 14);
		getContentPane().add(lblLibraryMedian);
		
		lblCompMedian = new JLabel(Double.toString(myAnalyzer(ComputersData)));
		lblCompMedian.setHorizontalAlignment(SwingConstants.CENTER);
		lblCompMedian.setBounds(295, 227, 36, 14);
		getContentPane().add(lblCompMedian);
		
		lblInfoMedian = new JLabel(Double.toString(myAnalyzer(InformationSystemData)));
		lblInfoMedian.setHorizontalAlignment(SwingConstants.CENTER);
		lblInfoMedian.setBounds(295, 270, 36, 14);
		getContentPane().add(lblInfoMedian);
		
		lblMoodleStdev = new JLabel(Double.toString(myAnalyzer(MoodleData)));
		lblMoodleStdev.setHorizontalAlignment(SwingConstants.CENTER);
		lblMoodleStdev.setBounds(423, 97, 36, 14);
		getContentPane().add(lblMoodleStdev);
		
		lblMoodleMean = new JLabel(Double.toString(myAnalyzer(MoodleData)));
		lblMoodleMean.setHorizontalAlignment(SwingConstants.CENTER);
		lblMoodleMean.setBounds(551, 97, 36, 14);
		getContentPane().add(lblMoodleMean);
		
		lblWebsiteStdev = new JLabel(Double.toString(myAnalyzer(WebsiteData)));
		lblWebsiteStdev.setHorizontalAlignment(SwingConstants.CENTER);
		lblWebsiteStdev.setBounds(423, 139, 36, 14);
		getContentPane().add(lblWebsiteStdev);
		
		lblWebsiteMean = new JLabel(Double.toString(myAnalyzer(WebsiteData)));
		lblWebsiteMean.setHorizontalAlignment(SwingConstants.CENTER);
		lblWebsiteMean.setBounds(551, 139, 36, 14);
		getContentPane().add(lblWebsiteMean);
		
		lblLibraryStdev = new JLabel(Double.toString(myAnalyzer(LibraryData)));
		lblLibraryStdev.setHorizontalAlignment(SwingConstants.CENTER);
		lblLibraryStdev.setBounds(423, 184, 36, 14);
		getContentPane().add(lblLibraryStdev);
		
		lblCompStdev = new JLabel(Double.toString(myAnalyzer(ComputersData)));
		lblCompStdev.setHorizontalAlignment(SwingConstants.CENTER);
		lblCompStdev.setBounds(423, 227, 36, 14);
		getContentPane().add(lblCompStdev);
		
		lblInfoStdev = new JLabel(Double.toString(myAnalyzer(InformationSystemData)));
		lblInfoStdev.setHorizontalAlignment(SwingConstants.CENTER);
		lblInfoStdev.setBounds(423, 270, 36, 14);
		getContentPane().add(lblInfoStdev);
		
		lblLibraryMean = new JLabel(Double.toString(myAnalyzer(LibraryData)));
		lblLibraryMean.setHorizontalAlignment(SwingConstants.CENTER);
		lblLibraryMean.setBounds(551, 184, 36, 14);
		getContentPane().add(lblLibraryMean);
		
		lblCompMean = new JLabel(Double.toString(myAnalyzer(ComputersData)));
		lblCompMean.setHorizontalAlignment(SwingConstants.CENTER);
		lblCompMean.setBounds(551, 227, 36, 14);
		getContentPane().add(lblCompMean);
		
		lblInfoMean = new JLabel(Double.toString(myAnalyzer(InformationSystemData)));
		lblInfoMean.setHorizontalAlignment(SwingConstants.CENTER);
		lblInfoMean.setBounds(551, 270, 36, 14);
		getContentPane().add(lblInfoMean);
		
	}
	
	public double myAnalyzer(int sysNum)
	{
	double ans=0;
	switch(sysNum)
		{
		case 1:Moodle= new Statistics(MoodleList);
				ans=Statistics.analyzer();
			break;
		case 2:Website= new Statistics(WebsiteList);
				ans=Statistics.analyzer();
			break;
		case 3:Library= new Statistics(LibraryList);
				ans=Statistics.analyzer();
			break;
		case 4:InformationSystem= new Statistics(InfoList);
				ans=Statistics.analyzer();
			break;
		case 5:Computers= new Statistics(CompList);
				ans=Statistics.analyzer();
			break;
			//default:return(this.mainGui.analyzer());
		}
	return(ans);
	}
	

}

